#include "square.hpp"

#ifdef _MAC_OS_
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#endif

#include <iostream>


void Square::draw() const
{
	  // Specify the color in RGB in [0;1] range.
  glColor3f(_color.x, _color.y, _color.z);

  // Begin OpenGL call : display two triangles to have a square
  // This square is positionned in [-0.5, -0.5] and have a width
  // and a height equals to 1.
  glBegin (GL_TRIANGLES);
  glVertex2f (_pos.x(), _pos.y());
  glVertex2f (_pos.x() + _dim.x(), _pos.y());
  glVertex2f (_pos.x(), _pos.y() + _dim.y());

  glVertex2f (_pos.x() + _dim.x(), _pos.y());
  glVertex2f (_pos.x(), _pos.y() + _dim.y());
  glVertex2f (_pos.x() + _dim.x(), _pos.y() + _dim.y());
  glEnd ();
}

void Square::setPosition(vec2f& v)
{
	_pos.copy(v);
}
void Square::setPosition(float x, float y)
{
	_pos.copy({x, y});
}

void Square::setSpeed(vec2f& v)
{
	_speed.copy(v);
}

void Square::setSpeed(float x, float y)
{
	_speed.copy({x, y});
}

void Square::update()
{
	// Définir les opérateurs permet d'alléger
	_pos += _speed;
	decelerate();
}


void Square::decelerate()
{
	// Idem
	_speed *= deceleration;
}

void Square::grow()
{
	_dim += 0.0001;
}

void Square::shrink()
{
	_dim -= 0.0001;
}
